package framework.classification.library;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import org.eclipse.emf.common.util.EList;



import framework.AnnuaireCocola;
import framework.HierarchyCocola;
import framework.classification.entities.ClAbstractEntity;
import framework.classification.entities.ClComponent;
import framework.classification.entities.ClFunctionProvided;
import framework.classification.entities.ClFunctionRequired;
import framework.classification.entities.ClInterfaceProvided;
import framework.classification.entities.ClInterfaceRequired;
import framework.classification.entities.lattice.erca.LatticeComponentErca;
import framework.classification.entities.lattice.erca.LatticeFunctionProvidedErca;
import framework.classification.entities.lattice.erca.LatticeFunctionRequiredErca;
import framework.classification.entities.lattice.erca.LatticeInterfaceProvidedErca;
import framework.classification.entities.lattice.erca.LatticeInterfaceRequiredErca;
import framework.entity.ACLComponent;
import framework.entity.ACLEntity;
import framework.entity.ACLFunction;
import framework.entity.ACLInterface;
import framework.io.out.LatticeToImage;
import framework.io.out.TableToLatex;

public class CompleteClassification extends AbstractClassfication{

	public static String MODE = "COMPLETE";
	
	public CompleteClassification(HierarchyCocola structure,
			AnnuaireCocola coco, String latticeGeneration) {
		super(structure, coco, latticeGeneration);
		// TODO Auto-generated constructor stub
	}

	public String getmode() {return MODE;}
	
	
	public void computeClassification(){
		
		computeFunctionClassfication2();
		computeInterfaceClassification2();
		computeComponentClassification();
		
	}

	public void computeComponentClassification() {
		
		//on recupere la definition de tous les composants de la structure
		//dans la liste listcompo
		ArrayList<ACLComponent> listcompo = new ArrayList<ACLComponent>();
		for (String compo : getStructure().getComponentsToInterface().keySet()){
			ACLComponent aclcompo = new ACLComponent(compo);
			ArrayList<ACLInterface> intersPro = getStructure().getComponentsProvided().get(aclcompo.getName());
			ArrayList<ACLInterface> intersReq  = getStructure().getComponentsRequired().get(aclcompo.getName());
			for (ACLInterface  aclinter : intersPro){
				aclcompo.addInterfacePro(aclinter);
			}
			for (ACLInterface  aclinter : intersReq){
				aclcompo.addInterfaceReq(aclinter);
			}
			listcompo.add(aclcompo);
		}
		
		
		
		ClComponent cl = new ClComponent(getLatticeGeneration()+"_Component",this,new LatticeComponentErca(),listcompo);
		cl.computeRelation();
		cl.computeLattice();
		clComponents.add(cl);
		
		
		//on recupere tous les composants reel
		for (String ent : cl.getRealReduced().keySet()){
			ACLComponent aclcompo = new ACLComponent(ent,ACLFunction.MODE2);
			
			if (!components.containsKey(aclcompo.getName()))
				components.put(aclcompo.getName(),new ArrayList<ClAbstractEntity>());
			
			if (!componentsName.containsKey(aclcompo.getName()))
				componentsName.put(aclcompo.getName(),aclcompo);
			
			components.get(aclcompo.getName()).add(cl);
		}
		
		//on reccupere tous les composants abstrait
		for (String ent : cl.getAbstractReduced().keySet()){
			ACLComponent aclcompo = new ACLComponent(ent,ACLFunction.MODE2);
			
				if (!components.containsKey(aclcompo.getName()))
				components.put(aclcompo.getName(),new ArrayList<ClAbstractEntity>());
			
			if (!componentsName.containsKey(aclcompo.getName()))
				componentsName.put(aclcompo.getName(),aclcompo);
			
			components.get(aclcompo.getName()).add(cl);
			
			
		}
	}

	

	public ArrayList<ClAbstractEntity> getConnection(ClInterfaceProvided cl) {
		ArrayList<ClAbstractEntity> sub = new ArrayList<ClAbstractEntity>();
		
		return null;
	}

	
	public ArrayList<ClAbstractEntity> getConnection(ClInterfaceRequired cl) {
		ArrayList<ClAbstractEntity> sub = new ArrayList<ClAbstractEntity>();
		
		return null;
	}

	
	

	
	
	

	

	
	
	
	
	
	
	
}
